package com.hx.io.filewiterandwriter;

import java.io.*;

/**
 * @author jxlgcmh
 * @create 2019-05-09 16:07
 */
public class Demo1 {
    public static void main(String[] args) {

        Reader reader = null;
        Writer writer = null;
        int len;
        char[] buf = new char[1024];
        try {
            File scr = new File("a.txt");
            File dst = new File("b.txt");
            reader = new FileReader(scr);
            writer = new FileWriter(dst, false);
            while ((len = reader.read(buf)) != -1) {
                writer.write(buf, 0, len);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (reader != null) {
                    reader.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }

            try {
                if (writer != null) {
                    writer.close();
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
